// src/components/AuthForm.tsx
import React from 'react';
import { Form, Input, Button } from 'antd';

interface UserData {
  username: string;
  password: string;
  email?: string; // 可选，适用于注册
}

interface AuthFormProps {
  onSubmit: (values: UserData) => void;
  isRegister?: boolean; // 是否为注册表单
}

const AuthForm: React.FC<AuthFormProps> = ({ onSubmit, isRegister = false }) => {
  const [form] = Form.useForm();

  return (
    <Form form={form} onFinish={onSubmit}>
      <Form.Item name="username" label="Username" rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item name="password" label="Password" rules={[{ required: true, message: 'Please input your password!' }]}>
        <Input.Password />
      </Form.Item>
      {isRegister && (
        <Form.Item name="email" label="Email" rules={[{ required: true, message: 'Please input your email!' }]}>
          <Input />
        </Form.Item>
      )}
      <Form.Item>
        <Button type="primary" htmlType="submit">{isRegister ? 'Register' : 'Login'}</Button>
      </Form.Item>
    </Form>
  );
};

export default AuthForm;
